package org.googlecode.openapi_java;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Date;

public class Profile {
    private long uid;
    private String firstName;
    private String lastName;
    private String nickname;
    private int sex;
    private String bdate;
    private int cityId;
    private int countryId;
    private String photo;
    private String photoMedium;
    private String photoBig;
    private boolean hasMobile;
    private int rate;
    private String homePhone;
    private String mobilePhone;
    private int universityId;
    private String universityName;
    private int facultyId;
    private String facultyName;
    private int graduation;
    
    public static Profile fromJSON(JSONObject json) throws JSONException {
        Profile profile = new Profile();
        //mandatory
        profile.uid = json.getLong("uid");
        profile.firstName = json.getString("first_name");
        profile.lastName = json.getString("last_name");
        //optional
        if (json.has("nickname")) profile.nickname = json.getString("nickname");
        if (json.has("sex")) profile.sex = json.getInt("sex");
        if (json.has("bdate")) profile.bdate = json.getString("bdate");
        
        if (json.has("city")) profile.cityId = json.getInt("city");
        if (json.has("country")) profile.countryId = json.getInt("country");
        
        if (json.has("photo")) profile.photo = json.getString("photo");
        if (json.has("photo_medium")) profile.photoMedium = json.getString("photo_medium");
        if (json.has("photo_big")) profile.photoBig = json.getString("photo_big");
        
        if (json.has("has_mobile")) profile.hasMobile =   json.getInt("has_mobile") == 1;
        if (json.has("rate")) profile.rate = json.getInt("rate");
        
        if (json.has("home_phone")) profile.homePhone = json.getString("home_phone");
        if (json.has("mobile_phone")) profile.mobilePhone = json.getString("mobile_phone");
        
        if (json.has("university")) profile.universityId = json.getInt("university");
        if (json.has("university_name")) profile.universityName = json.getString("university_name");
        
        if (json.has("faculty")) profile.facultyId = json.getInt("faculty");
        if (json.has("faculty_name")) profile.facultyName = json.getString("faculty_name");
        if (json.has("graduation")) profile.graduation = json.getInt("graduation");
        //todo
        return profile;
    }
    
    public void foo(){}
    
    @Override
    public String toString() {
        return "Profile{" +
                "uid=" + uid +
                ", firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", nickname='" + nickname + '\'' +
                ", sex=" + sex +
                ", bdate=" + bdate +
                ", cityId=" + cityId +
                ", countryId=" + countryId +
                ", photo='" + photo + '\'' +
                ", photoMedium='" + photoMedium + '\'' +
                ", photoBig='" + photoBig + '\'' +
                ", hasMobile=" + hasMobile +
                ", rate=" + rate +
                ", homePhone='" + homePhone + '\'' +
                ", mobilePhone='" + mobilePhone + '\'' +
                ", universityId=" + universityId +
                ", universityName='" + universityName + '\'' +
                ", facultyId=" + facultyId +
                ", facultyName='" + facultyName + '\'' +
                ", graduation=" + graduation +
                '}';
    }

	public long getUid() {
		return uid;
	}

	public String getFirstName() {
		return firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public String getNickname() {
		return nickname;
	}

	public int getSex() {
		return sex;
	}

	public String getBdate() {
		return bdate;
	}

	public int getCityId() {
		return cityId;
	}

	public int getCountryId() {
		return countryId;
	}

	public String getPhoto() {
		return photo;
	}

	public String getPhotoMedium() {
		return photoMedium;
	}

	public String getPhotoBig() {
		return photoBig;
	}

	public boolean isHasMobile() {
		return hasMobile;
	}

	public int getRate() {
		return rate;
	}

	public String getHomePhone() {
		return homePhone;
	}

	public String getMobilePhone() {
		return mobilePhone;
	}

	public int getUniversityId() {
		return universityId;
	}

	public String getUniversityName() {
		return universityName;
	}

	public int getFacultyId() {
		return facultyId;
	}

	public String getFacultyName() {
		return facultyName;
	}

	public int getGraduation() {
		return graduation;
	}
    
    
    
    
}
